<template>
  <div class="orderList">
    <div class="table">
      <div class="main_table">
        <el-table
          :header-cell-style="{ background: '#f5f7fa' }"
          :data="order_list"
        >
          <el-table-column label="订单id" prop="id"></el-table-column>
          <el-table-column label="买家id" prop="purchaser_id"></el-table-column>
          <el-table-column label="货品id" prop="product_specification_id.product_id"></el-table-column>
          <el-table-column label="规格" prop="product_specification_id.typeName"></el-table-column>
          <el-table-column label="单价" prop="product_specification_id.price"></el-table-column>
          <el-table-column label="总价" prop="total_price"></el-table-column>
          <el-table-column
            label="交易状态"
            align="center"
            column-key="tag"
            :filter-multiple="false"
            :filter-method="filterTag"
            :filters="order_status"
          >
           <template slot-scope="scope">{{ order_status[scope.row.deal_status].text }}</template>
          </el-table-column>
          <el-table-column label="交易操作">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="checkOrder(scope.row)">查看订单</el-button>
            </template>
          </el-table-column>
        </el-table>

      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'orderList',
  data() {
    return {
      order_list: [], // 订单列表
    };
  },
  computed: {
    // 订单状态
    order_status() {
      let status = this.$global.ORDERSTATUS
      let os = []
      for (let i in status) {
        os.push({
          text: status[i],
          value: i,  
        })
      }
      return os
    }
  },
  methods: {
    // 查看订单
    checkOrder(order) {
      this.$router.push({
        name: 'saler-orderDetail',
        params: {
          oid: order.id
        }
      })
    },
    handleCurrentChange(val) {
      this.currentPage = val;
    },
    filterTag(value, row, column) {
      return row.deal_status == value; //这个返回值就是返回你要展示的内容
    },
    async load() {
      let sid = this.$store.state.saler.saler_id
      let supplier_all_product = undefined
      await this.$API.getSupply().then(res => {
        if (res.status == 200 && sid) {
          supplier_all_product = []
          for (let obj of res.data) {
            if (obj.supplier_id == sid) supplier_all_product.push(obj)
          }
        }
      })
      let all_specification = []
      await this.$API.getSpecification().then(res => {
        if (res.status == 200) {
          for (let obj of res.data) {
            for (let obj2 of supplier_all_product) {
              if (obj.product_id == obj2.id) all_specification.push(obj)
            }
          }
        }
      })
      await this.$API.getProductOrder().then(res => {
        if(res.status == 200) {
          for (let order of res.data) {
            for (let obj of all_specification) {
              if (order.product_specification_id == obj.id) this.order_list.push(order)
            }
          }
        }
      })
    }
  },
  created() {
    this.load()
  },
};
</script>
<style>
</style>